In [7]:
%matplotlib inline
import seaborn as sns
import matplotlib.pyplot as plt

Algorithm

I want to, if it's possible, split students into pairs or groups of three. The boundary is the maximum number of rooms $N$ (ie. pairs or trios) created. If it's not possible to allocate enough rooms for students split into trios, I want to create exactly $N-1$ rooms and allocate students equally.

Visualization


In [8]:
import math

def new_rooms(x, N_max=15):
    if math.ceil(x / 2.) < N_max:
        rooms = math.ceil(x / 2.)
    elif math.ceil(x / 3.) < N_max:
        rooms = math.ceil(x / 3.)
    else:
        rooms = N_max - 1
    return rooms

In [10]:
X = range(0, 46)
Y = [new_rooms(x) for x in X]
plt.plot(X, Y)
plt.ylim(-1, 15)
plt.xlabel("Number of students")
plt.ylabel("Number of rooms")


Out[10]:
<matplotlib.text.Text at 0x7f07f6b4bb50>

As you can see, we never break the limit of 14 ($N - 1$) rooms. Hopefully classes won't be bigger than 20 students, because the more rooms there is, the worse performance will get.